home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / language / dino / dino_bot.1 / examples / smoothing / ex6.d < prev   
Encoding:
Text File  |  1991-05-21  |  3.4 KB  |  118 lines

  1. /* Copyright, 1990, Regents of the University of Colorado */
  2. /* This program is a smoothing-type algorithm which computes Pascal's
  3.  * triangle, to size M x N, by seting each element to the sum of the numbers
  4.  * directly above and to the left.  It illustrates user-defined mappings. */
  5.  
  6. #include "dino.h"
  7.  
  8. #define M 12
  9. #define N 12
  10. #define P1 4
  11. #define P2 4
  12.  
  13. environment node[P1:id1][P2:id2] {
  14.  
  15. #include "../inc/map.c"
  16.  
  17.                                 /* ==> A listing of this file appears after
  18.                                        after example 2.4. */
  19.  
  20.   map LeftUpOverlap = [block overlap 1,0][block overlap 1,0];
  21.  
  22.                                 /* ==> This is a user-defined mapping.  It
  23.                                        sets up a mapping which divides a 2D
  24.                                        array into blocks, and each environment
  25.                                        receives a copy of the one element
  26.                                        border strips to the west and north. */
  27.  
  28.   composite smooth (a, in iter)
  29.  
  30.   double distributed a[M][N] map LeftUpOverlap;
  31.   int iter;
  32.  
  33.   {
  34.     int i, j, k;        /* Looping variables */
  35.     map_var a1, a2;     /* Mapping variables */
  36.  
  37.     /* Setup the mapping variables */
  38.     set_map_var (M, P1, id1, 1, 0, &a1);
  39.     set_map_var (N, P2, id2, 1, 0, &a2);
  40.     limit_map_var (1, M-1, &a1);
  41.     limit_map_var (1, N-1, &a2);
  42.  
  43.     /* Repeat the smoothing process iter times */
  44.     for (k = 0; k < iter; k++) {
  45.  
  46.       /* Send out your data and receive it back again, if not the first
  47.        * iteration */
  48.       if (k != 0) {
  49.  
  50.         if (id1 != P1-1 || id2 != P2-1)
  51.           a[<a1.left,a1.right>][<a2.left,a2.right>]# =
  52.           a[<a1.left,a1.right>][<a2.left,a2.right>];
  53.  
  54.                                 /* ==> The lower right environment has no
  55.                                        data to send.  This if statement
  56.                                        prevents a run-time warning about it. */
  57.  
  58.         if (id1 != 0 || id2 != 0)
  59.           a[<a1.lover,a1.rover>][<a2.lover,a2.rover>]#;
  60.  
  61.                                 /* ==> The upper left environment has no
  62.                                        data to receive.  This if statement
  63.                                        prevents a run-time warning about it. */
  64.  
  65.       }
  66.  
  67.       /* Perform the computation, but only on non-edge nodes */
  68.       for (i = a1.left; i <= a1.right; i++)
  69.         for (j = a2.left; j <= a2.right; j++)
  70.           a[i][j] = a[i-1][j] + a[i][j-1];
  71.  
  72.     }
  73.   }
  74. }
  75.  
  76. environment host {
  77.  
  78.   void main ()
  79.  
  80.   {
  81.     double a[M][N];                     /* Input data */
  82.     int iter;                           /* Holds the iteration count */
  83.  
  84.     int i, j;                           /* Looping variables */
  85.  
  86.     /* Set up the initial data for a[][] */
  87.     for (i = 0; i < M; i++)
  88.       for (j = 0; j < N; j++)
  89.         a[i][j] = 0;
  90.     for (i = 0; i < M; i++)
  91.       a[i][0] = 1;
  92.     for (j = 0; j < N; j++)
  93.       a[0][j] = 1;
  94.  
  95.     /* Set up the variable which will contain the number of iterations */
  96.     iter = 7;
  97.  
  98.     /* Print out the initial data */
  99.     printf ("Initial data for a:\n");
  100.     for (i = 0; i < M; i++) {
  101.       for (j = 0; j < N; j++)
  102.         printf ("%7.1f", a[i][j]);
  103.       printf ("\n");
  104.     }
  105.  
  106.     /* Perform the computation */
  107.     smooth (a[][], iter)#;
  108.  
  109.     /* Printout the results */
  110.     printf ("Result data for a:\n");
  111.     for (i = 0; i < M; i++) {
  112.       for (j = 0; j < N; j++)
  113.         printf ("%5.1f", a[i][j]);
  114.       printf ("\n");
  115.     }
  116.   }
  117. }
  118.